/**
 * UninaDocentiSync - A Java application to synchronize Unina resources
 * Copyright (C) 2011  Fabio Scippacercola (nonplay.programmer@gmail.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

package uninadocentisync.guibeans;

import uninadocentisync.UninaDocentiSyncApp;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import uninadocenti.framework.Insegnamento;
import uninadocenti.framework.WebDocentiUnina;

/**
 *
 * @author user
 */
public class UninaDocentiSyncAppBean implements UninaDocentiSyncApp, java.io.Serializable {

    protected boolean overwriteFiles;
    public static final String PROP_OVERWRITEFILES = "overwriteFiles";

    /**
     * Get the value of overwriteFiles
     *
     * @return the value of overwriteFiles
     */
    public boolean isOverwriteFiles() {
        return overwriteFiles;
    }

    /**
     * Set the value of overwriteFiles
     *
     * @param overwriteFiles new value of overwriteFiles
     */
    public void setOverwriteFiles(boolean overwriteFiles) {
        boolean oldOverwriteFiles = this.overwriteFiles;
        this.overwriteFiles = overwriteFiles;
        propertyChangeSupport.firePropertyChange(PROP_OVERWRITEFILES, oldOverwriteFiles, overwriteFiles);
    }
    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    /**
     * Add PropertyChangeListener.
     *
     * @param listener
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Remove PropertyChangeListener.
     *
     * @param listener
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }

    protected ArrayList<Insegnamento> insegnamentiRegistrati = new ArrayList<Insegnamento>();
    public static final String PROP_INSEGNAMENTIREGISTRATI = "insegnamentiRegistrati";

    /**
     * Get the value of insegnamentiRegistrati
     *
     * @return the value of insegnamentiRegistrati
     */
    public List<Insegnamento> getInsegnamentiRegistrati() {
        return insegnamentiRegistrati;
    }


    protected File fileFolder;
    public static final String PROP_FILEFOLDER = "fileFolder";

    /**
     * Get the value of fileFolder
     *
     * @return the value of fileFolder
     */
    public File getFileFolder() {
        return fileFolder;
    }

    /**
     * Set the value of fileFolder
     *
     * @param fileFolder new value of fileFolder
     */
    public void setFileFolder(File fileFolder) {
        File oldFileFolder = this.fileFolder;
        this.fileFolder = fileFolder;
        propertyChangeSupport.firePropertyChange(PROP_FILEFOLDER, oldFileFolder, fileFolder);
    }

    protected boolean loginSetted;
    public static final String PROP_LOGINSETTED = "loginSetted";

    /**
     * Get the value of loginSetted
     *
     * @return the value of loginSetted
     */
    public boolean isLoginSetted() {
        return webDocenti.isLoginSetted();
    }

    public void doLogin(String username, String password) {
        boolean oldLoginSetted = webDocenti.isLoginSetted();
        webDocenti.setLogin(username, password);
        propertyChangeSupport.firePropertyChange(PROP_LOGINSETTED, oldLoginSetted, webDocenti.isLoginSetted());
    }

    public WebDocentiUnina getWebDocenti() {
        return webDocenti;
    }

    public boolean doRemoveInsegnamento(Insegnamento o) {
        List<Insegnamento> oldInsegnamentiRegistrati = insegnamentiRegistrati;
        insegnamentiRegistrati = (ArrayList<Insegnamento>)insegnamentiRegistrati.clone();
        final boolean b = insegnamentiRegistrati.remove(o);
        if (b) propertyChangeSupport.firePropertyChange(PROP_INSEGNAMENTIREGISTRATI, oldInsegnamentiRegistrati, insegnamentiRegistrati);
        return b;
    }

    public boolean doAddInsegnamento(Insegnamento e) {
        List<Insegnamento> oldInsegnamentiRegistrati = insegnamentiRegistrati;
        insegnamentiRegistrati = (ArrayList<Insegnamento>)insegnamentiRegistrati.clone();
        final boolean b = (!insegnamentiRegistrati.contains(e) && insegnamentiRegistrati.add(e));
        if (b) propertyChangeSupport.firePropertyChange(PROP_INSEGNAMENTIREGISTRATI, oldInsegnamentiRegistrati, insegnamentiRegistrati);
        return b;
    }
    


    protected WebDocentiUnina webDocenti = new WebDocentiUnina();
}
